package com.example.springbootdemo.tree;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Vector;

/**
 * @author cici
 */
public class TreeNode {

    int value;
    TreeNode left;
    TreeNode right;
    TreeNode(int x){
        value = x;
    }

    private TreeNode addTree(int x,int value){
           if (x == 1){
               this.left = new TreeNode(value);
               return left;
           }else {
               this.right = new TreeNode(value);
               return right;
           }
    }

    public void preorder(TreeNode node){
        if(node!=null){
            preorder(node.left);
            System.out.println(node.value);
//            preorder(node.left);
            preorder(node.right);
        }
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.addTree(1,2);
        TreeNode current = root.addTree(2,3);
        current = current.addTree(1,4);
        current = current.addTree(2,5);
        current.preorder(root);
    }
}
